import os
import rtconfig
from building import *

Import('SDK_LIB')

objs = []
cwd = GetCurrentDir()
list = os.listdir(cwd)

# add the general drivers.
src = Glob('board.c')
src += Glob('CubeMX_Config/Core/Src/stm32h7xx_hal_msp.c')

if GetDepend(['BSP_USING_QSPI_FLASH']):
    src += Glob('port/drv_qspi_flash.c')

if GetDepend(['BSP_USING_SPI_LCD_ILI9488']):
    src += Glob('drv_spi_ili9488.c')

if GetDepend(['BSP_USING_SPI_FLASH']):
    src += Glob('port/spi_flash_init.c')

if GetDepend(['BSP_USING_FS']):
    src += Glob('port/filesystem.c')

if GetDepend(['BSP_USING_SDIO_ARTPI']):
    src += Glob('port/drv_sdio.c')

if GetDepend(['BSP_USING_WIFI']):
    src += Glob('port/wifi_config.c')
    src += Glob('port/drv_wlan.c')    

if GetDepend(['BSP_USING_ETH_H750']):
    src += Glob('port/drv_eth.c')

if GetDepend(['PKG_USING_EASYFLASH']):
    src += Glob('port/ef_fal_port.c')

for item in list:
    if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
        objs = objs + SConscript(os.path.join(item, 'SConscript'))

path = [cwd]
path += [cwd + '/CubeMX_Config/Core/Inc']
path += [cwd + '/port']

startup_path_prefix = SDK_LIB

if rtconfig.CROSS_TOOL == 'gcc':
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h750xx.s']
elif rtconfig.CROSS_TOOL == 'keil':
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/arm/startup_stm32h750xx.s']
elif rtconfig.CROSS_TOOL == 'iar':
    src += [startup_path_prefix + '/STM32H7xx_HAL/CMSIS/Device/ST/STM32H7xx/Source/Templates/iar/startup_stm32h750xx.s']
    
# STM32H743xx || STM32H750xx || STM32F753xx
# You can select chips from the list above
CPPDEFINES = ['STM32H750xx']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
